<?php
/**
 * @Author: gan
 * @Description:
 * @File:  Cache
 * @Version: 1.0.0
 * @Date: 2022/5/24 10:23 上午
 */
declare(strict_types=1);

namespace RX\Component\CloudPrint\Cache;

use RX\Component\CloudPrint\Driver\FileDriver;
use Psr\SimpleCache\CacheInterface;

class Cache implements CacheInterface
{
    protected $driver;

    public function __construct(CacheConfig $cacheConfig)
    {
        $driver       = $cacheConfig->getDriver() ?: FileDriver::class;
        $this->driver = new $driver($cacheConfig->getDir(), $cacheConfig->getPrefix());
    }

    public function __call($name, $arguments)
    {
        return $this->driver->{$name}(...$arguments);
    }

    public function set($key, $value, $ttl = null)
    {
        return $this->__call(__FUNCTION__, func_get_args());
    }

    public function setMultiple($values, $ttl = null)
    {
        return $this->__call(__FUNCTION__, func_get_args());
    }

    public function delete($key)
    {
        return $this->__call(__FUNCTION__, func_get_args());
    }

    public function has($key)
    {
        return $this->__call(__FUNCTION__, func_get_args());
    }

    public function get($key, $default = null)
    {
        return $this->__call(__FUNCTION__, func_get_args());
    }

    public function deleteMultiple($keys)
    {
        return $this->__call(__FUNCTION__, func_get_args());
    }

    public function clear()
    {
        return $this->__call(__FUNCTION__, func_get_args());
    }

    public function getMultiple($keys, $default = null)
    {
        return $this->__call(__FUNCTION__, func_get_args());
    }
}
